//index.js
const app = getApp()
Page({
  data: {
    banners: [],
    recommendList: [],
    showwebview: false,
    href: '',
    footeractive: 0
  },
  onShareAppMessage(options) {
    return {
      title: '悦龄会 | 打造熟年品质生活',
      path: 'pages/index/index',
      imageUrl: '',
      success: function () {

      },
      fail: function () {

      },
      complete: function () {

      }
    }
  },
  bindtap(e) {
    let href = e.currentTarget.dataset.href
    let link = e.currentTarget.dataset.link
    if (link != 1) href = app.globalData.frontUrl + href
    wx.navigateTo({
      url: '/pages/middlewave/middlewave?href=' + encodeURIComponent(href),
    })
  },
  getBanners() {
    return new Promise((resolve, reject) => {
      wx.request({
        url: app.globalData.goodsBanner,
        method: 'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        data: { businessCode: 'INDEX_BANNER' }, 
        success: response => {
          let body = response.data
          if (body.code === 0) {
            this.setData({
              banners: body.data
            })
            resolve()
          }
          else {
            wx.showModal({
              title: '提示',
              content: body.msg,
            })
            resolve()
          }
        },
        fail: res => {
          wx.showModal({
            title: '提示',
            content: '获取失败，请稍后再试',
          })
        }
      })
    })
  },
  getRecommendList() {
    wx.request({
      url: app.globalData.goodsBanner,
      data: { businessCode: 'INDEX_REC_A' },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: response => {
        let body = response.data
        if (body.code === 0) {
          let recommendList = body.data
          this.setData({
            recommendList: recommendList
          })
        }
        else {
          wx.showModal({
            title: '提示',
            content: body.msg,
          })
        }
      },
      fail: res => {
        wx.showModal({
          title: '提示',
          content: '获取失败，请稍后再试',
        })
      }
    })
  },
  onLoad(options) {
    
  },
  onShow: function () {
    this.getBanners().then(this.getRecommendList())
  },
  onReady: function () {
  }
})
